#/bin/sh
#进程相关监控

process()
{
  count=`ps -ef | grep "$1" | grep -v grep | grep -v $0 | wc -l`
  return $count
}
# -w %{http_code} %{time_connect}:%{time_starttransfer}:%{time_total}
portcode()
{
  code=`curl -m 2 -I -o /dev/null -s -w %{http_code} "$1"`
  echo $code
}

dir=`dirname $0`
urls='192.168.1.131:80
192.168.1.131:8765/api/tenant/instrument/list'
ding=https://oapi.dingtalk.com/robot/send?access_token=605b3322af99285c0fe8426f42172fc3155efbac6885b8578e3750cce63d8378
send=0
title=端口警报
body="## $title \n "

for url in $urls
do

code=`portcode $url`
echo $url $code

if test "$code" != "200"
then
send=1
body+="- URL:$url   code:$code \n "
fi

done

if test $send -ne 0
then
sh $dir/push_ding.sh "$ding" "$title" "$body"
fi
